#ifndef CCMANAGER_H
#define CCMANAGER_H

#include "manager.h"

class UnfocusablePopupWindow;
class wxHtmlLinkEvent;
class wxHtmlWindow;
class wxListEvent;
class wxListView;
class wxScintillaEvent;

class CCManager : public Mgr<CCManager>, wxEvtHandler {
  public:
    friend class Mgr<CCManager>;
    friend class Manager;
    cbCodeCompletionPlugin* GetProviderFor( M_Code_Editor* ed = nullptr );
    void RegisterCallTipChars( const wxString& chars, cbCodeCompletionPlugin* registrant );
    void RegisterAutoLaunchChars( const wxString& chars, cbCodeCompletionPlugin* registrant );
    void NotifyDocumentation();
    void NotifyPluginStatus();
    void InjectAutoCompShow( int lenEntered, const wxString& itemList );
    bool ProcessArrow( int key );
    void UpdateEnvSettings();
  private:
    CCManager();
    ~CCManager();
    void OnCompleteCode( CodeBlocksEvent& event );
    void OnDeactivateApp( CodeBlocksEvent& event );
    void OnDeactivateEd( CodeBlocksEvent& event );
    void OnEditorOpen( CodeBlocksEvent& event );
    void OnEditorClose( CodeBlocksEvent& event );
    void OnEditorHook( M_Code_Editor* ed, wxScintillaEvent& event );
    void OnEditorTooltip( CodeBlocksEvent& event );
    void OnShowCallTip( CodeBlocksEvent& event );
    void OnAutocompleteSelect( wxListEvent& event );
    void OnAutocompleteHide( wxShowEvent& event );
    void OnDeferredCallTipShow( wxCommandEvent& event );
    void OnDeferredCallTipCancel( wxCommandEvent& event );
    void OnHtmlLink( wxHtmlLinkEvent& event );
    void OnTimer( wxTimerEvent& event );
    void OnMenuSelect( wxCommandEvent& event );
    void DoBufferedCC( M_Code_StyledTextCtrl* stc );
    void DoHidePopup();
    void DoShowDocumentation( M_Code_Editor* ed );
    void DoUpdateCallTip( M_Code_Editor* ed );
    enum Direction { Previous, Next };
    void AdvanceTip( Direction direction );
    void DoShowTips( const wxStringVec& tips, M_Code_StyledTextCtrl* stc, int pos, int argsPos, int hlStart, int hlEnd );
    void CallSmartIndentCCDone( M_Code_Editor* ed );
    typedef std::map< cbCodeCompletionPlugin*, std::set<wxChar> > CCPluginCharMap;
    CCPluginCharMap m_CallTipChars;
    CCPluginCharMap m_AutoLaunchChars;
    int m_EditorHookID;
    int m_AutocompPosition;
    int m_CallTipActive;
    int m_LastAutocompIndex;
    int m_LastTipPos;
    int m_WindowBound;
    bool m_OwnsAutocomp;
    typedef std::vector<cbCodeCompletionPlugin::CCCallTip> CallTipVec;
    CallTipVec m_CallTips;
    CallTipVec::const_iterator m_CurCallTip;
    std::map<int, size_t> m_CallTipChoiceDict;
    std::map<int, size_t> m_CallTipFuzzyChoiceDict;
    wxTimer m_CallTipTimer;
    wxTimer m_AutoLaunchTimer;
    wxTimer m_AutocompSelectTimer;
    wxSize m_DocSize;
    wxPoint m_DocPos;
    M_Code_Editor* m_pLastEditor;
    cbCodeCompletionPlugin* m_pLastCCPlugin;
    UnfocusablePopupWindow* m_pPopup;
    wxHtmlWindow* m_pHtml;
    int m_LastACLaunchState[2];
    std::vector<cbCodeCompletionPlugin::CCToken> m_AutocompTokens;
};

#endif
